<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>The navigation bar</title>
</head>
<body>
<div th:fragment="nav">
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">麻将社区</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/index">麻将社区</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a class="navbar-brand" href="#">问答</a></li>
                    <li><a class="navbar-brand" href="#">专栏</a></li>
                    <li><a class="navbar-brand" href="#">活动</a></li>
                </ul>
                <!--搜索-->
                <form class="navbar-form navbar-left" action="/search" method="get">
                    <div class="form-group">
                        <input type="text" class="form-control" name="search" placeholder="搜索你感兴趣的话题...">
                    </div>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
                <!--右侧表格-->
                <ul class="nav navbar-nav navbar-right">
                    <!--提问-->
                    <li th:if="${session.user != null}">
                        <a href="/publish">
                            <span class="glyphicon glyphicon-question-sign navigation-glyphicon" aria-hidden="true"
                                  data-toggle="tooltip" data-placement="left" title="提问"></span>
                        </a>
                    </li>
                    <!--通知-->
                    <li th:if="${session.user != null}">
                        <a href="/profile/replies">
                            <span class="glyphicon glyphicon-bell navigation-glyphicon"
                                  aria-hidden="true" data-toggle="tooltip"
                                  data-placement="bottom" title="通知"></span>
                            <span class="badge" th:text="${session.unreadCount}"></span>
                        </a>
                    </li>
                    <!--头像-->
                    <li class="dropdown" th:if="${session.user != null}">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                           aria-haspopup="true"
                           aria-expanded="false">
                            <span style="margin-top: 0; padding-top: 0">
                                <img th:src="${session.user.getAvatarUrl()}" class="img-rounded navigation-img-size"
                                     alt="Image">
                                <span class="caret"></span>
                            </span>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a th:href="${'/people/' + session.user.getName()}">
                                    <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>
                                    <span>个人主页</span>
                                </a>
                            </li>
                            <li>
                                <a th:href="@{/account/setting/basic}">
                                    <span class="glyphicon glyphicon-cog" aria-hidden="true"></span>
                                    <span>设置</span>
                                </a>
                            </li>
                            <li>
                                <a href="/logout">
                                    <span class="glyphicon glyphicon-off" aria-hidden="true"></span>
                                    <span>退出登录</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li th:if="${session.user == null}">
                        <a id="login-or-register" th:href="@{https://github.com/login/oauth/authorize(
                        client_id='6b94612764d44e4ce138',scope='user',state=1,
                        redirect_uri=${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #httpServletRequest.getServerPort() + '/callback'})}">登录/注册</a>
                        <script type="application/javascript">
                            var locationHref = window.location.href;
                            var dynamicHref = document.getElementById("login-or-register").getAttribute("href");
                            document.getElementById("login-or-register").setAttribute("href", dynamicHref + "?locationHref=" + locationHref);
                        </script>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>
</body>
</html>
